import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
	list = '/journey/bsTravelgroupMaintuortravellinerecord/list',
	getListByMainId = '/journey/bsTravelgroupMaintuortravellinerecord/getListByMainId',
	getMsgsByGroup = '/journey/bsTravelgroupTravelistgroup/getMsgsByGroup',
	getMsgByPreline = '/journey/bsTravelgroupTravelistgroup/getMsgByPreline',
	save = '/journey/bsTravelgroupMaintuortravellinerecord/add',
	edit = '/journey/bsTravelgroupMaintuortravellinerecord/edit',
	editSelf = '/journey/bsTravelgroupMaintuortravellinerecord/editSelf',
	saveSelf = '/journey/bsTravelgroupMaintuortravellinerecord/saveSelf',
	closeOrOpen = '/journey/bsTravelgroupMaintuortravellinerecord/closeOrOpen',
	deleteOne = '/journey/bsTravelgroupMaintuortravellinerecord/delete',
	deleteBatch = '/journey/bsTravelgroupMaintuortravellinerecord/deleteBatch',
	importExcel = '/journey/bsTravelgroupMaintuortravellinerecord/importExcel',
	exportXls = '/journey/bsTravelgroupMaintuortravellinerecord/exportXls',
	updateOrderStats = '/journey/bsTravelgroupMaintuortravellinerecord/editOrderStatus',
	uploadStats = '/journey/bsTravelgroupMaintuortravellinerecord/editTravelStatus',
}
export const uploadStats = (params) => {
	return defHttp.post({ url: Api.uploadStats, params });
}
export const updateOrderStats = (params) => {
	return defHttp.post({ url: Api.updateOrderStats, params });
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
export const getMsgsByGroup = (params) =>
	defHttp.get({ url: Api.getMsgsByGroup, params });

export const getMsgByPreline = (params) =>
	defHttp.get({ url: Api.getMsgByPreline, params });
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
	defHttp.get({ url: Api.list, params });

export const getListByMainId = (params) =>
	defHttp.get({ url: Api.getListByMainId, params });

/**
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
	return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
		handleSuccess();
	});
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
	createConfirm({
		iconType: 'warning',
		title: '确认删除',
		content: '是否删除选中数据',
		okText: '确认',
		cancelText: '取消',
		onOk: () => {
			return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
				handleSuccess();
			});
		}
	});
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {

	let url = isUpdate ? Api.edit : Api.save;
	return defHttp.post({ url: url, params });
}
export const saveOrUpdateSelf = (params, isUpdate, isCopy) => {

	//组装数据
	params.type = 'Self'
	if (!params.createuserid) {
		params.createuserid = '侣途'
	}
	console.log(params)
	let extInfor = {
		msg: params.msg,
		virtualUserNum: params.virtualUserNum,
		groupUserSize: params.groupUserSize,
		destination: params.destination,
		keyCode: params.keyCode,
		tags: params.tags,
		startdateStr: params.startdateSj,//上架时间
		enddateStr: params.enddateStr,//下架时间
		pdtIds: params.pdtIds,
		descriptionOfFees: params.descriptionOfFees,
		retrofitRule: params.retrofitRule,
		mustSee: params.mustSee,
		suggestedTime: params.suggestedTime,
		xjSelect: params.xjSelect,
		sjSelect: params.sjSelect
	}
	params.pretravelcarlist = params.pretravelcarlist1 //.split(',')
	params.extInfor = JSON.stringify(extInfor)

	let url = isUpdate ? Api.editSelf : Api.saveSelf;
	if (isCopy) {
		url = Api.saveSelf
		params.id = null;
	}

	return defHttp.post({ url: url, params });
}
export const closeOrOpenApi = (params) => {
	return defHttp.post({ url: Api.closeOrOpen, params });
}